querysalesContract()
function querysalesContract() {
    $.ajax({
        url:root.member.queryMainCustomerContractSetup,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "mainCustomerId":sessionStorage.getItem("mainCustomerId"),

        }),
        success: function (data) {
            if(data.errorCode==0){

                $("#signAddress").val(data.data.signAddress),
                $("#buyerName").val(data.data.buyerName),
                $("#mandator").val(data.data.mandator),
                $("#mandatorMobile").val(data.data.mandatorMobile),
                $("#bankName").val(data.data.bankName),
                $("#bankAccount").val(data.data.bankAccount)
                if(data.data.saleContract==1){
                    $("#saleContract1").prop('checked',true);
                }else if(data.data.saleContract==0){
                    $("#saleContract2").prop('checked',true);
                }
            if(data.data.remarkList!="" && data.data.remarkList!=null){
                $("#additionalInformation").html("")
                for (var g = 0; g <data.data.remarkList.length; g++) {
                    if(g==0){
                        $("#additionalInformation").append(' <div class="row ml-10" >\n' +
                            '                                        <label class="form-label f-l label-right w-80">附加信息：</label>\n' +
                            '                                        <input  maxlength="100" type="text" class="input-text radius formControls w-150 ml-10 lh-26" value="'+data.data.remarkList[0]+'"  placeholder="请输入" name="additionalInformations"  style="width: 10%">\n' +
                            '\n' +
                            ' <a onclick="additionalInformation()">增加</a>'+

                            '                                    </div>')
                    }else {
                        $("#additionalInformation").append(' <div class="row ml-10" >\n' +
                            '                                        <label class="form-label f-l label-right w-80">附加信息：</label>\n' +
                            '                                        <input  maxlength="100" type="text" class="input-text radius formControls w-150 ml-10 lh-26" value="'+data.data.remarkList[g]+'"  placeholder="请输入" name="additionalInformations"  style="width: 10%">\n' +
                            '\n' +
                            ' <a onclick="deleteitionalInformation(this)">删除</a>'+

                            '                                    </div>')
                    }

                }
            }

                if(data.data.categoryOne==0){
                    $("#categoryOne").prop('checked',true);
                }
                if(data.data.categoryTwo==0){
                    $("#categoryTwo").prop('checked',true);
                }
                if(data.data.categoryThree==0){
                    $("#categoryThree").prop('checked',true);
                }
                if(data.data.categoryFour==0){
                    $("#categoryFour").prop('checked',true);
                }
                if(data.data.materielNumber==0){
                    $("#materielNumber").prop('checked',true);
                }
                if(data.data.taxName==0){
                    $("#taxName").prop('checked',true);
                }
                if(data.data.taxCode==0){
                    $("#taxCode").prop('checked',true);
                }
                if(data.data.outCargoTime==0){
                    $("#outCargoTime").prop('checked',true);
                }

                if(data.data.settleType==1){
                    $("#settleType1").prop('checked',true);
                }else if(data.data.settleType==2){
                    $("#settleType2").prop('checked',true);
                }
                if(data.data.categoryOne==0 &&data.data.categoryTwo==0&&data.data.categoryThree==0&&data.data.categoryFour==0&&data.data.materielNumber==0&&data.data.taxName==0&&data.data.taxCode==0&&data.data.outCargoTime==0){
                    $("#checkboxs").prop('checked',true);
                }else {
                    $("#checkboxs").prop('checked',false);

                }


            }else {
                $.Huimodalalert(data.msg,2000);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}

//附加信息
function additionalInformation() {
    $("#additionalInformation").append(' <div class="row ml-10" >\n' +
        '                                        <label class="form-label f-l label-right w-80">附加信息：</label>\n' +
        '                                        <input maxlength="100" type="text" class="input-text radius formControls w-150 ml-10 lh-26"  placeholder="请输入" name="additionalInformations"  style="width: 10%" >\n' +
        '\n' +
        ' <a onclick="deleteitionalInformation(this)">删除</a>'+
        '                                    </div>')
}
//删除附加信息
function deleteitionalInformation(val) {
    $(val).parent().remove()
}

//全选
function checkboxdatas() {
    var saleArea=$("input[name='checkboxall']")
    if($("#checkboxs").is(':checked')==true){
        for(var i = 0; i < saleArea.length; i++) {
            saleArea[i].checked = true;
        }
    }else {
        for(var i = 0; i < saleArea.length; i++) {
            saleArea[i].checked = false;
        }
    }
}
//子级选中
checkboxdatasall()
function checkboxdatasall() {
    var saleArea=$("input:checkbox[name='checkboxall']")
    var saleArea2=$("input:checkbox[name='checkboxall']:checked")
    if(saleArea2.length==saleArea.length){
        $("#checkboxs").prop("checked", true)
    }else {
        $("#checkboxs").prop("checked", false)
    }
}
//保存
function addsalesContract() {

   /* if($("input[name=picStatus]:checked").val()==undefined){
        $.Huimodalalert("请编辑生效状态",2000);
        return false;
    }*/
   var remarks=""
    for (var g = 0; g < $("input[name=additionalInformations]").length; g++) {
        remarks += $("input[name=additionalInformations]")[g].value+ "&p";
    }
    console.log(remarks)
    //去掉最后一个逗号(如果不需要去掉，就不用写)
    if (remarks.length > 0) {
        remarks = remarks.substr(0, remarks.length - 2);
    }
   console.log(remarks)
    var categoryOnes=""
    var categoryTwos=""
    var categoryThrees=""
    var categoryFours=""
    var materielNumbers=""
    var taxNames=""
    var taxCodes=""
    var outCargoTimes=""
    if($("#categoryOne").is(":checked")==true){
        categoryOnes=0
    }else if($("#categoryOne").is(":checked")==false){
        categoryOnes=1
    }
    if($("#categoryTwo").is(":checked")==true){
        categoryTwos=0
    }else if($("#categoryTwo").is(":checked")==false){
        categoryTwos=1
    }
    if($("#categoryThree").is(":checked")==true){
        categoryThrees=0
    }else if($("#categoryThree").is(":checked")==false){
        categoryThrees=1
    }
    if($("#categoryFour").is(":checked")==true){
        categoryFours=0
    }else if($("#categoryFour").is(":checked")==false){
        categoryFours=1
    }
    if($("#materielNumber").is(":checked")==true){
        materielNumbers=0
    }else if($("#materielNumber").is(":checked")==false){
        materielNumbers=1
    }
    if($("#taxName").is(":checked")==true){
        taxNames=0
    }else if($("#taxName").is(":checked")==false){
        taxNames=1
    }
    if($("#taxCode").is(":checked")==true){
        taxCodes=0
    }else if($("#taxCode").is(":checked")==false){
        taxCodes=1
    }
    if($("#outCargoTime").is(":checked")==true){
        outCargoTimes=0
    }else if($("#outCargoTime").is(":checked")==false){
        outCargoTimes=1
    }

    $.ajax({
        url:root.member.saveMainCustomerContractSetup,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "mainCustomerId":sessionStorage.getItem("mainCustomerId"),
            "signAddress":$("#signAddress").val(),
            "buyerName":$("#buyerName").val(),
            "mandator":$("#mandator").val(),
            "mandatorMobile":$("#mandatorMobile").val(),
            "bankName":$("#bankName").val(),
            "bankAccount":$("#bankAccount").val(),
            "saleContract":$("input[name=saleContract]:checked").val(),
            "categoryOne":categoryOnes,
            "categoryTwo":categoryTwos,
            "categoryThree":categoryThrees,
            "categoryFour":categoryFours,
            "materielNumber":materielNumbers,
            "taxName":taxNames,
            "taxCode":taxCodes,
            "outCargoTime":outCargoTimes,
            "remark":remarks,
            "settleType":$("input[name=settleType]:checked").val()

        }),
        success: function (data) {
                    if(data.errorCode==0){
                        layer.msg('添加成功', {icon: 6, time: 1000});
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                            parent.layer.close(index);
                        }, 1000)

                    }else {
                        $.Huimodalalert(data.msg,2000);
                    }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//取消
function cancelbtn() {
    var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
    parent.layer.close(index);
}
